package futrue;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import utils.ThreadUtils;

/**
 * Created by wuzhao on 2017/3/6 0006.
 */
public class CallableAndFuture {
    public static void main(String[] args) throws ExecutionException, TimeoutException, InterruptedException {
        Future<Boolean> booleanFuture = callFuture("名称.", 11L);
        Boolean aBoolean = booleanFuture.get();
        System.out.println("主线程.");
        System.out.printf("==="+aBoolean);
        System.exit(0);
    }

    public static Future<Boolean> callFuture(final String name, final Long id){
        Future<Boolean> submit = ThreadUtils.submit(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                Thread.sleep(5000);
                System.out.println(name + id);
                return true;
            }
        });
        return submit;
    }
}
